from pydantic import BaseModel
from typing import Dict, Optional, List
from datetime import datetime

class QuestionBase(BaseModel):
    subject: str
    vehicle_type: str
    question_type: str
    exam_type: str
    content: str
    options: Dict[str, str]
    correct_answer: str
    explanation: Optional[str] = None

class QuestionCreate(QuestionBase):
    pass

class QuestionUpdate(QuestionBase):
    pass

class Question(QuestionBase):
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        orm_mode = True

class QuestionResponse(BaseModel):
    success: bool
    data: List[Question]
    total: int

class AnswerCheck(BaseModel):
    user_answer: str

class AnswerResponse(BaseModel):
    correct: bool
    correct_answer: str
    explanation: Optional[str] = None

class RecordCreate(BaseModel):
    subject: str
    score: float
    answers: Dict[str, Dict[str, bool]]  # {question_id: {"correct": bool}}

class Record(RecordCreate):
    id: int
    user_id: int
    created_at: datetime

    class Config:
        orm_mode = True 